package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eMessageType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.fivehero.FiveHeroModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

/**
 * 使用五熊爭霸殘卷
 */
public class UseFiveHeroBookGoodsBag extends BaseUseGoods {

	public UseFiveHeroBookGoodsBag(GamePlayer player, GoodsInfo goodsInfo, long param) {
		super(player, goodsInfo, param);
	}

	@Override
	int checkUse(long count) {
		return 0;
	}

	@Override
	UseGoodsResult executeUse(long count) {
		UseGoodsResult result = new UseGoodsResult();
		Property reward = new Property();
		for (long i = 0; i < count; i++) {
			OpenGoodsBagResult openResult = GoodsBagMgr.getRandomGoods(goodsInfo.getGoodsId());
			result.getRewardList().add(PropertyHelper.parsePropertyToString(openResult.getReward()));
			reward.addProperty(openResult.getReward());
			if(openResult.getNotice() == 1){
				WorldMessageMgr.worldNotify(player, eMessageType.OpenGoodsBagNotice.getValue(), player.getUserInfo().getCity(), player.getTitleId(),
						player.getUserInfo().getNickName(), goodsInfo.getGoodsId(), PropertyHelper.parsePropertyToString(openResult.getReward()));
			}
		}
		player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Bag, eLogMoneyType.OpenGoodsBag);
		result.setReward(PropertyHelper.parsePropertyToString(reward));
		BigInteger oneAddValue = goodsInfo.getParamList().get(0);
		if(oneAddValue.longValue() != 0){
			player.getModule(FiveHeroModule.class).bookValueAdd(count * oneAddValue.longValue(),count);
		}
		return result;
	}
}
